package com.pansoft.openplanet.activity;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.chat.activity.BaseActivity;
import com.efounder.recycleviewhelper.CommonAdapter;
import com.efounder.recycleviewhelper.MultiItemTypeAdapter;
import com.efounder.recycleviewhelper.base.ViewHolder;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.ExchangeRecordBean;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;

public class ExchangeRecordListActivity extends BaseActivity {

    private TextView tvTitle;
    private ImageView ivBack;

    private RefreshLayout mRefreshLayout;
    private RecyclerView rcvExchangeRecord;

    private CommonAdapter mRecordListAdapter;

    private ArrayList<ExchangeRecordBean> mRecordList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exchange_record_list);

        mRecordList = new ArrayList<>();

       // mRecordList.add(new ExchangeRecordBean());
        //mRecordList.add(new ExchangeRecordBean());

        initView();
    }

    private void initView() {
        ivBack = (ImageView) findViewById(R.id.iv_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout_exchange_record);
        rcvExchangeRecord = (RecyclerView) findViewById(R.id.rcv_exchange_recored);
        rcvExchangeRecord.setLayoutManager(new LinearLayoutManager(this));

        tvTitle.setText(ResStringUtil.getString(R.string.open_planet_exchange_record));

        mRefreshLayout.setEnableLoadMore(false);
        initData();

        mRecordListAdapter = new CommonAdapter<ExchangeRecordBean>(this, R.layout.item_exchange_record_list,mRecordList) {

            @Override
            protected void convert(ViewHolder holder, ExchangeRecordBean bean, int position) {
                bean = mRecordList.get(position);
                //id
                String tvExchangeId = bean.getExchangeId();
                //转出总数
                String tvExchangeCount = bean.getExchangeCount();
                //转账类型
                String tvExchangeType = bean.getExchangeType();
                //转账时间
                String tvExchangeTime = bean.getExchangeTime();

//                holder.setText(R.id.tv_exchange_id, "0x1852****5455");
//                holder.setText(R.id.tv_exchange_count, "-1.24");
//                holder.setText(R.id.tv_exchange_type, "转出能量");
//                holder.setText(R.id.tv_exchange_time, "2018-04-27 15：36");
//                holder.setImageResource(R.id.iv_exchange_type, R.drawable.iv_exchange_out);

            }

        };

        rcvExchangeRecord.setAdapter(mRecordListAdapter);
        mRecordListAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                ExchangeRecordBean recordBean = mRecordList.get(position);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

        refreshAndLoad();
    }

    /**
     * 请求网络
     */
    private void initData(){

    }

    /**
     * 下拉刷新和上拉加载
     */
    private void refreshAndLoad(){


        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                //刷新完成调用
                mRefreshLayout.finishRefresh();
            }
        });
    }

}
